import request from "@/utils/request";
import getUserProfileName from "@/utils/getUserProfile";

// // 查询油企
// export function getEnterpriseListApi(query) {
//     return request({
//       url: '/enterprise/info/list',
//       method: 'get',
//       params: query
//     })
// }

// 查询油站
export function getStationListApi(query) {
  return request({
    url: "/station/message/list",
    method: "get",
    params: query,
  });
}

// 新增车队卡
export function addFleetCardApi(fleetCardForm) {
  return request({
    url: "/fleet/card",
    method: "post",
    data: fleetCardForm,
  });
}

// 修改车队卡
export function updateFleetCardApi(id, fleetCardForm) {
  return request({
    url: `/fleet/card/${id}`,
    method: "put",
    data: fleetCardForm,
  });
}

// 车队卡分页列表
export function getFleetCardListApi(enterpriseId) {
  return request({
    url: "/fleet/card/page",
    method: "get",
    params: enterpriseId,
  });
}

// 车队卡充值
export function teamCardRechargeApi(fleetCardRechargeForm) {
  return request({
    url: `/fleet/card/recharge/${fleetCardRechargeForm.id}`,
    method: "put",
    data: fleetCardRechargeForm,
  });
}

// 车队卡充值记录列表
export function getFleetCardRechargeListApi(fleetCardId) {
  return request({
    url: "/fleetCard/recharge/page",
    method: "get",
    params: fleetCardId,
  });
}

// 车队卡消费记录
export async function getTeamCardOrderListApi(consumerId) {
  // 判断是否的admin 账号，如果不是，传 isDelete = 0 到后端，如果是则不用传参
  const isDelete = await getUserProfileName();
  let queryPlass;
  if (isDelete) {
    queryPlass = consumerId;
  } else {
    queryPlass = { ...consumerId, isDeleted: 0 };
  }

  return request({
    url: `/station/order/list/`,
    method: "get",
    params: queryPlass,
  });
}

export async function getList(consumerId) {
  // 判断是否的admin 账号，如果不是，传 isDelete = 0 到后端，如果是则不用传参
  const isDelete = await getUserProfileName();
  let queryPlass;
  if (isDelete) {
    queryPlass = consumerId;
  } else {
    queryPlass = { ...consumerId, isDeleted: 0 };
  }

  return request({
    url: `/fleet/payOrder/list`,
    method: "get",
    params: queryPlass,
  });
}

// 删除车队卡
export function delParentCardApi(ids) {
  return request({
    url: `/fleet/card/${ids}`,
    method: "delete",
  });
}

// 车队卡配置子卡的分配方式
export function setSonCardAllocationTypeApi(params) {
  return request({
    url: `/fleet/card/allocationType/${params.allocationType}/id/${params.id}`,
    method: "put",
  });
}

// 主卡回收所有子卡
export function recoveryAllSonCardApi(id) {
  return request({
    url: `/fleet/card/recovery/${id}`,
    method: "put",
  });
}

// 获取主卡信息
export function getParentCardInfoApi(id) {
  return request({
    url: `/fleet/card/${id}`,
    method: "get",
  });
}

// 确认开票  /station/order/goToInvoice    post请求
export function goToInvoice(data) {
  return request({
    url: "/station/order/goToInvoice",
    method: "post",
    data: data,
  });
}

// GET /fleetCard/recharge/cdk/balance 车队卡余额明细
export function cdkBalance(query) {
  return request({
    url: "/fleetCard/recharge/cdk/balance",
    method: "get",
    params: query,
  });
}

// GET /fleetCard/recharge/balance/statistics 余额明细统计
export function balanceStatistics(query) {
  return request({
    url: "/fleetCard/recharge/balance/statistics",
    method: "get",
    params: query,
  });
}

// GET /fleetCard/recharge/fleetName 查询车队卡列表
export function rechargeFleetName(query) {
  return request({
    url: "/fleetCard/recharge/fleetName",
    method: "get",
    params: query,
  });
}


// 余额调整
export function updateTeamCardBlanceApi(data){
  return request({
    url:'/fleet/card/adjust/balance',
    method:'post',
    data:data
  })
}